home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / CDlog / CStarterApp.p < prev    next >
Encoding:
Text File  |  1990-11-12  |  7.8 KB  |  318 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CStarterApp.p                                                                    }
  4. {}
  5. {        Application methods for a typical application.                                    }
  6. {}
  7. {        Copyright © 1989, Symantec Corporation.  All rights reserved.            }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CStarterApp;
  13.  
  14. interface
  15.  
  16. uses
  17.     TCL, StarterIntf, {}
  18.     CDlog, UExampleDlog;            {For example dialog}
  19.  
  20. implementation
  21.  
  22.  
  23. {**}
  24. { * IStarterApp}
  25. { *}
  26. { *    Initialize the application. Your initialization method should}
  27. { *    at least call the inherited method. If your application class}
  28. { *    defines its own instance variables or global variables, this}
  29. { *    is a good place to initialize them.}
  30. { *}
  31. { **}
  32.  
  33. procedure CStarterApp.IStarterApp;
  34.  
  35.     begin
  36.         IApplication(4, 20480, 2048);
  37.  
  38.         { The parameters to IApplication are the number of times to call MoreMasters,    }
  39.         { the number of bytes of heap space to reserve for monitoring                        }
  40.         { low memory situations, and the credit limit for memory requests.                }
  41.         {   Four (4) is a reasonable number of MoreMasters calls,                            }
  42.         { but you should determine a good number for your application                        }
  43.         { by observing the heap using Lightsbug,                                                }
  44.         { TMON, or Macsbug. Set this parameter to zero, give your                            }
  45.         { program a rigorous work-out, then look at the heap and count                        }
  46.         { how many master pointer blocks have been allocated. Master                        }
  47.         { pointer blocks are nonrelocatable and have a size of $100                            }
  48.         { (hex). You should call MoreMasters at least this many                                }
  49.         { times -- add a few extra just to be safe. The purpose of all                        }
  50.         { this preflighting is to prevent heap fragmentation. You                                }
  51.         { don't want the Memory Manager to call MoreMasters and                            }
  52.         { create a nonrelocatable block in the middle of your heap. By                        }
  53.         { calling MoreMasters at the very beginning of the program,                            }
  54.         { you ensure that these blocks are allocated in a group at the                        }
  55.         { bottom of the heap.                                                                        }
  56.         {   The memory reserve is a safeguard for handling low memory                    }
  57.         { conditions and is used by the GrowMemory method in                                }
  58.         { CApplication (check there for more comments). In general,                            }
  59.         { your program should never request a memory block greater                        }
  60.         { than this reserve size without explicitly checking in                                }
  61.         { advance whether there is enough free memory to satisfy the                        }
  62.         { the request.                                                                                }
  63.         {   The credit limit specifies a cut-off level for memory                                }
  64.         { requests which can tap the memory reserve. Requests larger                        }
  65.         { than this size will not use the memory reserve when the                            }
  66.         { system pleads for more memory.                                                        }
  67.  
  68.     end;
  69.  
  70.  
  71. {**}
  72. { * MakeDesktop}
  73. { *}
  74. { *    Build a desktop that supports modal dialogs. }
  75. { *}
  76. { **}
  77. procedure CStarterApp.MakeDesktop;                            {For example dialog}
  78.     var
  79.         aDeskTop: CDModalDesktop;
  80.  
  81.     begin
  82.         new(aDesktop);                    { Use a CDModalDesktop Desktop    }
  83.         gDeskTop := aDeskTop;        { Set the global variable                 }
  84.         gDesktop.IDesktop(SELF);    { Send the init message                    }
  85.     end;
  86.  
  87. {**}
  88. { * SetUpFileParameters}
  89. { *}
  90. { *    In this routine, you specify the kinds of files your}
  91. { *    application opens.}
  92. { *}
  93. { **}
  94.  
  95. procedure CStarterApp.SetUpFileParameters;
  96.  
  97.     begin
  98.  
  99.         inherited SetUpFileParameters;    { Be sure to call the default method }
  100.  
  101.         {*}
  102. {         **    sfNumTypes is the number of file types}
  103. {         **    your application knows about.}
  104. {         **    sfFileTypes[] is an array of file types.}
  105. {         **    You can define up to 4 file types in}
  106. {         **    sfFileTypes[].}
  107. {         **}
  108. {         *}
  109.  
  110.         sfNumTypes := 1;
  111.         sfFileTypes[0] := 'TEXT';
  112.  
  113.         {*}
  114. {         **    Although it's not an instance variable,}
  115. {         **    this method is a good place to set the}
  116. {         **    gSignature global variable. Set this global}
  117. {         **    to your application's signature. You'll use it}
  118. {         **    to create a file (see CFile.CreateNew).}
  119. {         **}
  120. {         *}
  121.  
  122.         gSignature := '????';
  123.     end;
  124.  
  125.  
  126.  
  127. {**}
  128. { * SetUpMenus }
  129. { *}
  130. { * Set up menus which must be created at run time, such as a}
  131. { * Font menu. You can eliminate this method if your application}
  132. { * does not have any such menus.}
  133. { *}
  134. {**}
  135.  
  136. procedure CStarterApp.SetUpMenus;
  137.     begin
  138.  
  139.         inherited SetUpMenus;            { Superclass takes care of adding        }
  140.                                         {   menus specified in a MBAR id = 1    }
  141.                                         {   resource                                }
  142.  
  143.         { Add your code for creating run-time menus here    }
  144.     end;
  145.  
  146.  
  147. {**}
  148. { * DoCommand}
  149. { *}
  150. { *    Your application will probably handle its own commands.}
  151. { *    Remember, the command numbers from 1-1023 are reserved.}
  152. { *    The file TCL.p contains all the predefined TCL commands.}
  153. { *}
  154. { *    Be sure to call the default method, so you can get}
  155. { *    the default behavior for standard commands.}
  156. { *}
  157. { **}
  158.  
  159. procedure CStarterApp.DoCommand (theCommand: longint);
  160.  
  161.     begin
  162.         case theCommand of
  163.             cmdAbout:                         {For example dialog}
  164.                 begin
  165.                 DoExampleDlog;
  166.             end;
  167.  
  168.             otherwise                                        { Invoke inherited method     }
  169.                 inherited DoCommand(theCommand);        { to handle other commands    }
  170.  
  171.         end;
  172.     end;
  173.  
  174.  
  175. {**}
  176. { *}
  177. { * UpdateMenus }
  178. { *}
  179. { *     Perform menu management tasks}
  180. { *}
  181. {**}
  182.  
  183. procedure CStarterApp.UpdateMenus;
  184.     var
  185.         topWindow: CWindow;
  186.         modal: boolean;
  187.  
  188.     begin
  189.         inherited UpdateMenus;            { Enable standard commands            }
  190.  
  191.         { Enable the commands handled by your Application class    }
  192.  
  193. { ----------------------------------------------------------------------------- }
  194. { The rest of this method was added by John Cardinal for the CDlog example application }
  195. { ----------------------------------------------------------------------------- }
  196.  
  197.         { Support for modal windows:}
  198.         {    If top window is modal, we must disable items that are not    }
  199.         {    valid while the modal window is up.                                        }
  200.  
  201.         topWindow := gDeskTop.GetTopWindow;
  202.         if Member(topWindow, CDlogWind) then
  203.             modal := CDlogWind(topWindow).GetModal
  204.         else
  205.             modal := FALSE;
  206.  
  207.         if modal then begin
  208.             gBartender.DisableCmd(cmdNew);
  209.             gBartender.DisableCmd(cmdOpen);
  210.             gBartender.DisableCmd(cmdClose);
  211.             gBartender.DisableCmd(cmdAbout);
  212.             gBartender.DisableCmd(cmdToggleClip);
  213.         end
  214.         else
  215.             gBartender.EnableCmd(cmdAbout);
  216.     end;
  217.  
  218.  
  219. {**}
  220. { * Exit}
  221. { *}
  222. { *    Chances are you won't need this method.}
  223. { *    This is the last chance your application gets to clean up}
  224. { *    things like temporary files before terminating.}
  225. { *}
  226. { **}
  227.  
  228. procedure CStarterApp.Exit;
  229.  
  230.     begin
  231.     { your exit handler here }
  232.     end;
  233.  
  234.  
  235. {**}
  236. { * CreateDocument}
  237. { *}
  238. { *    The user chose New from the File menu.}
  239. { *    In this method, you need to create a document and send it}
  240. { *    a NewFile message.}
  241. { *}
  242. { **}
  243.  
  244. procedure CStarterApp.CreateDocument;
  245.  
  246.     var
  247.         theDocument: CStarterDoc;
  248.  
  249.     begin
  250.  
  251.         new(theDocument);
  252.  
  253.         {*}
  254. {         **    Send your document an initialization}
  255. {         **    message. The first argument is the document's}
  256. {         **    supervisor (the application). The second}
  257. {         **    argument is TRUE if the document is printable.}
  258. {         **}
  259. {         *}
  260.  
  261.         theDocument.IStarterDoc(SELF, TRUE);
  262.  
  263.         {*}
  264. {         **    Send the document a NewFile message.}
  265. {         **    The document will open a window, and}
  266. {         **    set up the heart of the application.}
  267. {         **}
  268. {         *}
  269.  
  270.         theDocument.NewFile;
  271.     end;
  272.  
  273.  
  274. {**}
  275. { * OpenDocument}
  276. { *}
  277. { *    The user chose Open… from the File menu.}
  278. { *    In this method you need to create a document}
  279. { *    and send it an OpenFile message.}
  280. { *}
  281. { *    The macSFReply is a good SFReply record that contains}
  282. { *    the name and vRefNum of the file the user chose to}
  283. { *    open.}
  284. { *}
  285. { **}
  286.  
  287. procedure CStarterApp.OpenDocument (macSFReply: SFReply);
  288.  
  289.     var
  290.         theDocument: CStarterDoc;
  291.  
  292.     begin
  293.  
  294.         new(theDocument);
  295.  
  296.         {*}
  297. {         **    Send your document an initialization}
  298. {         **    message. The first argument is the document's}
  299. {         **    supervisor (the application). The second}
  300. {         **    argument is TRUE if the document is printable.}
  301. {         **}
  302. {         *}
  303.  
  304.         theDocument.IStarterDoc(SELF, TRUE);
  305.  
  306.         {*}
  307. {         **    Send the document an OpenFile message.}
  308. {         **    The document will open a window, open}
  309. {         **    the file specified in the macSFReply record,}
  310. {         **    and display it in its window.}
  311. {         **}
  312. {         *}
  313.  
  314.         theDocument.OpenFile(macSFReply);
  315.     end;
  316.  
  317.  
  318. end.